/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.octopeer.main;

import java.util.ArrayList;

import net.octopeer.core.Peer;
import net.octopeer.core.PeerNode;
import net.octopeer.core.Neighbor;
import net.octopeer.core.Resource;
import net.octopeer.core.config.PeerNodeConfig;
import net.octopeer.core.config.NeighborListConfig;
import net.octopeer.core.config.ResourceListConfig;
import net.octopeer.network.Listener;

/**
 *
 * @author andria
 */
public class Octopeer {
    public static void main(String[] args) throws Exception {
        // create and configure the current peer node
        Peer peer = new Peer();
        
        PeerNodeConfig pnc = new PeerNodeConfig();
        PeerNode pn = pnc.readPeerNodeConfig();
        
        NeighborListConfig nlc = new NeighborListConfig();
        ArrayList<Neighbor> nl =  nlc.readNeighborListConfig();
        
        ResourceListConfig rlc = new ResourceListConfig();
        ArrayList<Resource> rl =  rlc.readResourceListConfig();
        
        peer.setNode(pn);
        peer.setNeighborList(nl);
        peer.setResourceList(rl);
        
        // create service, userinterface
        OctopeerService oService = new OctopeerService(peer);
        OctopeerUI oUI = new OctopeerUI(peer, oService);
        oUI.start();
        
        // create start listener service
        Listener oListener = new Listener(peer.getNode().getNodePort(), oService);
        oListener.startListener();
        
//        peer.toXMLFile("./conf/peerOut.xml");
    }
}
